package com.jied.duodian.service.Impl;

import com.jied.duodian.dao.DdAddressDAO;
import com.jied.duodian.entity.DdAddress;
import com.jied.duodian.entity.DdAddressExample;
import com.jied.duodian.service.DdAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 *
 * @author LiJie
 * @date Created on 2020/10/28
 * WWW https://github.com/j6l
 */
@Service
@Transactional
public class DdAddressServiceImpl implements DdAddressService {

    @Autowired
    DdAddressDAO ddAddressDAO;

    @Override
    @Cacheable(cacheNames = "qt", keyGenerator = "keyGenerator")
    public DdAddress getAddressByid(Integer id) {
        return ddAddressDAO.selectByPrimaryKey( id );
    }

    @Override
    public List<DdAddress> getAddressByusername(String name) {
        DdAddressExample example = new DdAddressExample();
        DdAddressExample.Criteria criteria = example.createCriteria();
        criteria.andUserNameEqualTo( name );
        return ddAddressDAO.selectByExample( example );
    }

    @Override
    public Integer updataAddress(DdAddress address) {
        return ddAddressDAO.updateByPrimaryKeySelective( address );
    }

    @Override
    public Integer delAddress(Integer id) {
        return ddAddressDAO.deleteByPrimaryKey( id );
    }

    @Override
    public Integer addAddressList(DdAddress address) {
        return ddAddressDAO.insertSelective( address );
    }
}
